#include <iostream>
#include <vector>
#include <stack>
using namespace std;

class Solution
{
public:
    int evalRPN(vector<string> &tokens)
    {
        stack<int> st;
        for (auto token : tokens)
        {
            if (token.size() == 1 && (token == "+" || token == "-" || token == "*" || token == "/"))
            {
                int b = st.top(); // 注意先弹出右操作数
                st.pop();
                int a = st.top(); // 再弹出左操作数
                st.pop();
                if (token == "+")
                    st.push(a + b);
                else if (token == "-")
                    st.push(a - b);
                else if (token == "*")
                    st.push(a * b);
                else if (token == "/")
                    st.push(a / b);
            }
            else
                st.push(stoi(token));
        }
        return st.top();
    }
};